package dao.daocontrollers;

import java.lang.reflect.Type;

import workerswithdb.IDAOGarage;
import workerswithdb.IDAOMaster;
import workerswithdb.IDAOOrder;

public class GeneratorQueries {
	
	private final String ordersInsert="insert into orders(number_order,status_order,filling_date, begining_date,deadline_date,price, id_master, id_garage) values(?,?,?,?,?,?,?,?)";
	private final String garagesInsert="insert into garages(number_garage,fullness_garage) values(?,?)";
	private final String mastersInsert = "insert into masters(master_name ,employment_master) values(?,?)";
	private final String readOrder="select * from orders where number_order=?";
	private final String readGarage= "select * from garages where number_garage=?";
	private final String readMaster="select * from masters where master_name=?";
	private final String idGarage= "select id_garage from garages where number_garage=?";
	private final String idMaster="select id_master from masters where master_name =?";
	private final String idOrder= "select id_order from orders where number_order =?";
	private final String updateMaster="update masters set employment_master=? where master_name=?";
	private final String updateGarage="update garages set fullness_garage=? where number_garage=?";
	private final String shiftOrderDate="update orders set deadline_date=? where id_order=?";
	private final String markOrder= "update orders set status_order=? where id_order=?";
	private final String deleteGarage="delete from garages where id_garage=?";
	private final String deleteMaster="delete from masters where id_master =?";
	
	
	
	public String generatorQueryInsert(Type t){
		String insertQuery = "";
		if(t.equals(IDAOOrder.class)){
			insertQuery=ordersInsert;
		}else if(t.equals(IDAOGarage.class)){
			insertQuery=garagesInsert;
		}else if(t.equals(IDAOMaster.class)){
			insertQuery=mastersInsert;
		}
		return insertQuery;
		
	}
	
	public String generatorQueryRead(Type t){
		String readQuery="";
		if(t.equals(IDAOOrder.class)){
			readQuery=readOrder;
		}else if(t.equals(IDAOGarage.class)){
			readQuery=readGarage;
		}else if(t.equals(IDAOMaster.class)){
			readQuery=readMaster;
		}
		return readQuery;
	}

	public String generatorQueryId(Type t){
		String idQuery="";
		if(t.equals(IDAOOrder.class)){
			idQuery=idOrder;
		}else if(t.equals(IDAOGarage.class)){
			idQuery=idGarage;
		}else if(t.equals(IDAOMaster.class)){
			idQuery=idMaster;
		}
		return idQuery;
		
	}
	
	public String generatorQueryUpdate(Type t,Type typeUpdateParameter){
		String queryUpdate="";
		if(t.equals(IDAOOrder.class)){
			if(typeUpdateParameter.equals(String.class)){
				queryUpdate=markOrder;
			}else{
				queryUpdate=shiftOrderDate;
			}
			
		}else if(t.equals(IDAOGarage.class)){
			queryUpdate=updateGarage;
		}else if(t.equals(IDAOMaster.class)){
			queryUpdate=updateMaster;
		}
		return queryUpdate;		
	}
	
	public String generatorQueryDelete(Type t){
		String deleteQuery="";
		if(t.equals(IDAOGarage.class)){
			deleteQuery=deleteGarage;
		}else{
			deleteQuery=deleteMaster;
		}
		return deleteQuery;
	}
	
}
